package top.wardyan.wtask.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.jfinal.plugin.activerecord.Record;

import top.wardyan.base.common.annotation.Service;
import top.wardyan.base.common.db.kits.ProcKit;
import top.wardyan.base.common.db.po.WRecord;
import top.wardyan.wtask.service.IProcService;

@Service
public class ProcServiceImpl implements IProcService {

	private static final cn.hutool.log.Log log = cn.hutool.log.Log.get();

	@Override
	public void yp_tapd_clearworkhour(Timestamp date, String man) {
	}

	@Override
	public void yp_tapd_workhour(Timestamp date, String man, String cust, Integer tapdid, Float hour,
			Boolean isFinish) {
	}

	@Override
	public List<Record> yp_tapd_date(String man, Timestamp date) {
		WRecord rcs = ProcKit.query("yp_tapd_date", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public String yp_tapd_mail(String man, Timestamp date) {
		WRecord rcs = ProcKit.query("yp_tapd_mail", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		String rs = "";
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getFirst().getStr("rResult");
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_feishu_week(String man, Timestamp date) {
		WRecord rcs = ProcKit.query("yp_query_feishu_week", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_tapd_week(String man, Timestamp date) {
		WRecord rcs = ProcKit.query("yp_query_tapd_week", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_tapd_month(String man, Timestamp date) {
		WRecord rcs = ProcKit.query("yp_query_tapd_month", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_tapd_weektask(String man, Timestamp date) {
		WRecord rcs = ProcKit.query("yp_query_tapd_weektask", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_tapd_weekemergency(String man, Timestamp date) {

		WRecord rcs = ProcKit.query("yp_query_tapd_weekemergency", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_qry_weeksummary(Timestamp date) {
		// 取这一天里的从按周一开始算第一天
		// date = new Timestamp(DateUtil.range(date, 3).getTime() + 1000 * 60 * 60 * 24);;
		// 这个日期在过程里自动转了

		WRecord rcs = ProcKit.query("yp_qry_weeksummary", new HashMap<String,Object>(){{
			this.put("pBDate", date);
			this.put("pEDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_listempls(Boolean all) {
		WRecord rcs = ProcKit.query("yp_listempls", new HashMap<String,Object>(){{
			if(all) {
				this.put("pTag", 1);
			}
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public Record yp_qry_preimporttime() {

		WRecord rcs = ProcKit.exec("yp_qry_preimporttime", new HashMap<String,Object>());
		Record rs = new Record();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getFirst();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_task_qryweekalltask(Timestamp pBDate, Timestamp pEDate) {

		WRecord rcs = ProcKit.query("yp_task_qryweekalltask", new HashMap<String,Object>(){{
			this.put("pBDate", pBDate);
			this.put("pEDate", pEDate);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_task_qryweekstatistics(Timestamp pBDate, Timestamp pEDate) {

		WRecord rcs = ProcKit.query("yp_task_qryweekstatistics", new HashMap<String,Object>(){{
			this.put("pBDate", pBDate);
			this.put("pEDate", pEDate);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_listgroups() {
		WRecord rcs = ProcKit.query("yp_listgroups", new HashMap<String,Object>());
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_tapd_emergencys() {

		WRecord rcs = ProcKit.query("yp_query_tapd_emergencys", new HashMap<String,Object>());
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_feishu_date(String man, Timestamp date) {

		WRecord rcs = ProcKit.query("yp_query_feishu_date", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_progressing(String man, Timestamp date) {

		WRecord rcs = ProcKit.query("yp_query_progressing", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_storyprogressing(String man, Timestamp date) {

		WRecord rcs = ProcKit.query("yp_query_storyprogressing", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_performance(String man, Timestamp date) {

		WRecord rcs = ProcKit.query("yp_query_performance", new HashMap<String,Object>(){{
			this.put("pMan", man);
			this.put("pDate", date);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_story(Timestamp begin, Timestamp end, String man, String text, String cust, String status) {

		WRecord rcs = ProcKit.query("yp_query_story", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pMan", man);
			this.put("pText", text);
			this.put("pCust", cust);
			this.put("pStatus", status);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_story_count(Timestamp begin, Timestamp end, String man, String text, String cust, String status, Boolean isCust) {

		WRecord rcs = ProcKit.query("yp_query_story_count", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pMan", man);
			this.put("pText", text);
			this.put("pCust", cust);
			this.put("pStatus", status);
			this.put("pIsCust", isCust);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	@Override
	public List<Record> yp_query_task(Timestamp begin, Timestamp end, String man, String text, String cust, String status) {

		WRecord rcs = ProcKit.query("yp_query_task", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pMan", man);
			this.put("pText", text);
			this.put("pCust", cust);
			this.put("pStatus", status);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_task_count(Timestamp begin, Timestamp end, String man, String text, String cust, String status, Boolean isCust) {

		WRecord rcs = ProcKit.query("yp_query_task_count", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pMan", man);
			this.put("pText", text);
			this.put("pCust", cust);
			this.put("pStatus", status);
			this.put("pIsCust", isCust);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}
	

	

	@Override
	public List<Record> yp_query_task_max(Timestamp begin, Timestamp end, String man, String text, String cust, String status) {

		WRecord rcs = ProcKit.query("yp_query_task_max", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pMan", man);
			this.put("pText", text);
			this.put("pCust", cust);
			this.put("pStatus", status);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_sqlchecker_view(Timestamp begin, Timestamp end, Integer status, Integer tag, Integer sID) {

		WRecord rcs = ProcKit.query("yp_sqlchecker_view", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pStatus", status);
			this.put("pTag", tag);
			this.put("pExtID", sID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_sqlchecker_item_view(Integer mID, Integer datatype, Integer status, Integer level,String owner, String text, Integer tag) {
		WRecord rcs = ProcKit.query("yp_sqlchecker_item_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
			this.put("pDataType", datatype);
			this.put("pStatus", status);
			this.put("pLevel", level);
			this.put("pOwner", owner);
			this.put("pText", text);
			this.put("pTag", tag);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_sqlchecker_duplicate_view(Integer mID) {
		WRecord rcs = ProcKit.query("yp_sqlchecker_duplicate_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_sqlchecker_allitem(Timestamp begin, Timestamp end, Integer datatype, Integer status,Integer level, String owner, String text, Integer tag) {
		WRecord rcs = ProcKit.query("yp_sqlchecker_allitem", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pDataType", datatype);
			this.put("pStatus", status);
			this.put("pLevel", level);
			this.put("pOwner", owner);
			this.put("pText", text);
			this.put("pTag", tag);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public List<Record> yp_sqlchecker_allduplicate(Timestamp begin, Timestamp end, String owner, String text,Integer tag) {
		WRecord rcs = ProcKit.query("yp_sqlchecker_allitem", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pOwner", owner);
			this.put("pText", text);
			this.put("pTag", tag);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public void yp_sqlchecker_markbill(Integer pID, Integer status) {
		ProcKit.exec("yp_sqlchecker_markbill", new HashMap<String,Object>(){{
			this.put("pID", pID);
			this.put("pStatus", status);
		}});
	}

	@Override
	public void yp_sqlchecker_markitem(Integer mID, Integer dID, Integer status) {
		ProcKit.exec("yp_sqlchecker_markitem", new HashMap<String,Object>(){{
			this.put("pID", mID);
			this.put("pDID", dID);
			this.put("pStatus", status);
		}});
	}

	@Override
	public List<Record> yp_sqlchecker_itemcost(Integer mID) {
		WRecord rcs = ProcKit.query("yp_sqlchecker_itemcost", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public String yp_sqlchecker_report(Integer mID) {
		String rs = "";
		WRecord rcs = ProcKit.query("yp_sqlchecker_report", new HashMap<String,Object>(){{
			this.put("pID", mID);
		}});
		//List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			Record r = rcs.getFirst();
			if(r.getStr("rStr") != null) {
				rs = r.getStr("rStr");
			}
			
		}
		return rs;
	}
	


	@Override
	public void yp_sqlchecker_markduplicate(Integer mID, Integer dID, Integer status) {
		ProcKit.exec("yp_sqlchecker_markduplicate", new HashMap<String,Object>(){{
			this.put("pID", mID);
			this.put("pDID", dID);
			this.put("pStatus", status);
		}});
	}

	@Override
	public List<Record> yp_listhoursbycust(Timestamp begin, Timestamp end, Integer datatype) {
		WRecord rcs = ProcKit.query("yp_listhoursbycust", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pDataType", datatype);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
			
		}
		return rs;
	}

	@Override
	public void yp_devreport_build(Integer id) {
		ProcKit.exec("yp_devreport_build", new HashMap<String,Object>(){{
			this.put("pID", id);
		}});
	}

	@Override
	public void yp_devreport_build_mark(Integer id) {
		ProcKit.exec("yp_devreport_build_mark", new HashMap<String,Object>(){{
			this.put("pID", id);
		}});
	}

	@Override
	public List<Record> yp_devreport_view(Timestamp begin, Timestamp end, Integer datatype, Integer pageNo,Integer pageSize) {
		WRecord rcs = ProcKit.query("yp_devreport_view", new HashMap<String,Object>(){{
			this.put("pBeginDate", begin);
			this.put("pEndDate", end);
			this.put("pDataType", datatype);
			this.put("pPageNo", pageNo);
			this.put("pPageSize", pageSize);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public List<Record> yp_devreport_hour_view(Integer mID) {
		WRecord rcs = ProcKit.query("yp_devreport_hour_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public List<Record> yp_devreport_team_view(Integer mID) {
		WRecord rcs = ProcKit.query("yp_devreport_team_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public List<Record> yp_devreport_task_view(Integer mID) {
		WRecord rcs = ProcKit.query("yp_devreport_task_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public List<Record> yp_devreport_emergency_view(Integer mID) {
		WRecord rcs = ProcKit.query("yp_devreport_emergency_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public List<Record> yp_devreport_custhour_view(Integer mID, Integer datatype) {
		WRecord rcs = ProcKit.query("yp_devreport_custhour_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
			this.put("pDataType", datatype);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public List<Record> yp_devreport_item_view(Integer mID) {
		WRecord rcs = ProcKit.query("yp_devreport_item_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public List<Record> yp_devreport_date_view(Integer mID) {
		WRecord rcs = ProcKit.query("yp_devreport_date_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public List<Record> yp_devreport_feishu_view(Integer mID) {
		WRecord rcs = ProcKit.query("yp_devreport_feishu_view", new HashMap<String,Object>(){{
			this.put("pMID", mID);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

	@Override
	public Integer yp_getid(String tableName, String field, Integer cnt) {
		Integer rs = 0;
		WRecord rcs = ProcKit.exec("yp_getid", new HashMap<String,Object>(){{
			this.put("pTableName", tableName);
			this.put("pField", field);
			this.put("pQty", cnt);
		}});
		if(rcs != null && rcs.getFirst() != null) {
			Record r = rcs.getFirst();
			if(r != null && r.getStr("rResult") != null) {
				rs = r.getInt("rResult");
			}
		}
		return rs;
	}

	@Override
	public List<Record> yp_query_feishu_list(Timestamp date, String man) {
		WRecord rcs = ProcKit.query("yp_query_feishu_list", new HashMap<String,Object>(){{
			this.put("pDate", date);
			this.put("pMan", man);
		}});
		List<Record> rs = new ArrayList<>();
		if(rcs != null && rcs.getFirst() != null) {
			rs = rcs.getRecords();
		}
		return rs;
	}

}
